var mysql = require("mysql");

// import mysql from "mysql";

var pool = mysql.createPool({
  connectionLimit: 10,
  host: "localhost",
  user: "root",
  password: "be648943",
  database: "laowangbook",
  // database: "laowangmusic",
  multipleStatements: true,
  // debug: true,
});

// 常规SQL
let query = function (sql, arr = [], callback) {
  // 建立连接
  pool.getConnection(function (err, connection) {
    if (err) {
      throw err;
      return;
    }
    connection.query(sql, arr, function (error, result, fields) {
      // 将连接返回道连接池中，准备由其他人重复使用
      connection.release();
      if (error) throw error;
      //执行回调函数，酱数据返回
      callback && callback(result, fields);
    });
  });
};

module.exports = {
  query,
  pool,
};
